const app = getApp();
Page({
	data: {
		height: 0,
		pos: 'fixed',
		inputValue : '',
		StatusBar: app.globalData.StatusBar,
		CustomBar: app.globalData.CustomBar,
	},
	onLoad() {
		let that = this;
		let baseUrl = app.globalData.baseUrl;
		// 获取用户信息
		wx.getSetting({
			success: res => {
				if (!res.authSetting['scope.userInfo']) {
					wx.redirectTo({
						url: '/pages/guide/guide'
					});
				}
				// else {

				// }
			}
		});

		function getInfo() {
			wx.getUserInfo({
				success: function (res) {
					let rawData = res.rawData,
						signature = res.signature,
						encryptedData = res.encryptedData,
						iv = res.iv;
					wx.login({
						success(res) {
							if (res.code) {
								wx.request({
									url: baseUrl + '/api/user/wxlogin',
									data: {
										code: res.code,
										rawData: rawData,
										signature: signature,
										encryptedData: encryptedData,
										iv: iv
									},
									method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
									// header: {}, // 设置请求的 header
									success: function (res) {
										if (res.data.code == 200) {
											app.globalData.loginInfo = res.data.data;
											wx.setStorage({
												key: 'loginInfo',
												data: res.data.data,
												success: function(res){
													// success
												},
												fail: function() {
													// fail
												},
												complete: function() {
													// complete
												}
											})
										} else {
											getInfo();
										}
									},
									fail: function () {
										wx.showModal({
											title: 'sorry',
											content: '遇到未知原因，请退出小程序',
											showCancel: false,
											success(res) {
												if (res.confirm) {
													console.log("遇到未知bug请退出小程序");
												}
											}
										});
									},
									complete: function () {}
								});
							}
						}
					});
				}
			});
		}
		getInfo();
	},
	
});